package com.example.demo.web;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.example.demo.auth.ClientToken;
import com.example.demo.service.TokenService;

@RestController
@RequestMapping("/token")
public class TokenController {
	
	@Autowired
	TokenService srv;
	
	@Autowired
	HttpServletRequest request;
	
	@RequestMapping("")
	public String token(String appid, String nonce, String sign, String timestamp ) {
		ClientToken clientToken = new ClientToken();
		clientToken.setAppid(appid);
		clientToken.setNonce(nonce);
		clientToken.setSign(sign);
		clientToken.setTimestamp(timestamp);
		
		return srv.generateToken(clientToken, request);
	}
	
}
